﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;
using System.IO;

namespace GenIX
{
    public partial class MainForm : Form
    {
        // <Events>
        // ======================= События ===================================
        // </Events>

        // <MainFormLoad>
        // Инициализация при загрузки формы
        // </MainFormLoad>
        private void MainForm_Load(object sender, EventArgs e)
        {
            // <GenIX> "GenIX — Генерация графического интерфейса пользователя по XML описанию" </GenIX>

            tbCurUser.Text = "USER";
            Valid.Enabled = true;
            notValid.Enabled = false;
            editToolStripMenuItem.Enabled = false;

            newToolStripMenuItem.Enabled = false;          
            interfaceToolStripMenuItem.Enabled = false;
            xml_fileToolStripMenuItem.Enabled = false;

            closeToolStripMenuItem.Enabled = false;
            close_allToolStripMenuItem.Enabled = false;
            openToolStripMenuItem.Enabled = true;
            saveToolStripMenuItem.Enabled = false;
            ListsEditing.Enabled = false;

            RegistrationForm regform = new RegistrationForm();
            regform.Owner = this;
            regform.AutoLogin();
        }

       
        // <FilesListBox>
        // При смене индекса списка файлов
        // </FilesListBox>
        private void openedFilesListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (openedFilesListBox.SelectedIndex >= 0)
            {
                filename = openedFilesListBox.SelectedItem.ToString();
                Parsing(filename, false, 0);
                buildTree(filename);
                saveToolStripMenuItem.Enabled = false;
            }
            else return;
        }


        // <InterfacePanel>
        // При клике на Панель
        // </InterfacePanel>
        private void interfacePanel_MouseClick(object sender, MouseEventArgs e)
        {
            interfacePanel.Focus();
        }


        // <TreeView>
        // При двойном клике на дерево
        // </TreeView>
        private void hierarchyTreeView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Parsing(filename, false, hierarchyTreeView.SelectedNode.Index);
        }


        // <tbCurUserChanged>
        // При смене пользователя
        // </tbCurUserChanged>
        private void tbCurUser_TextChanged(object sender, EventArgs e)
        {
            if (tbCurUser.Text == "USER")
            {
                newToolStripMenuItem.Enabled = false;
                interfaceToolStripMenuItem.Enabled = false;
                xml_fileToolStripMenuItem.Enabled = false;
            }
            else
            {
                newToolStripMenuItem.Enabled = true;
                interfaceToolStripMenuItem.Enabled = true;
                xml_fileToolStripMenuItem.Enabled = true;
                ListsEditing.Enabled = true;
            }
        } 

    }
}